package com.eascs.message.service.impl;

import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.utils.StringUtils;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.app.runtime.RuntimeSetting;
import com.eascs.common.util.DateUtils;
import com.eascs.message.dao.O2OMessageDao;
import com.eascs.message.dao.O2OMessageEaoaDao;
import com.eascs.message.entiy.O2OMessage;
import com.eascs.message.form.FefundConstants;
import com.eascs.message.form.O2oMessageForm;
import com.eascs.message.form.O2oMessageTimer;
import com.eascs.notify.sms.SmsNotifier;
import com.eascs.notify.sms.SmsNotifyRequest;
import com.eascs.notify.sms.SmsNotifyResponse;
import com.eascs.notify.sms.SmsSendType;
import com.eascs.paymentdetail.service.O2oPaymentDetailService;
import com.eascs.paymentdetail.vo.O2oPaymentDetailVo;
import com.eascs.web.sso.User;
import com.eascs.workflow.common.entity.sys.SysMessage;
import com.eascs.workflow.common.service.sys.SysPermissionService;
import com.eascs.workflow.common.vo.ModelResult;


@Service
public class O2oMessageServiceImpl  {

	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	O2OMessageDao o2OMessageDao;

	@Autowired
	O2OMessageEaoaDao o2OMessageEaoaDao;
	
	@Autowired
	O2oLoanapplyService o2oLoanapplyService;
	
	@Autowired
	O2oLoanUserService o2oLoanUserService;
	
	@Autowired
	O2oPaymentDetailService o2oPaymentDetailService;
	
	@Reference
	SysPermissionService  sysPermissionService;
	@Reference
	private SmsNotifier smsNotifier;
	
	@SuppressWarnings("unused")
	private RuntimeSetting runtimeSetting = RuntimeSetting.get();
	
	public PageResult<Object[]> messageList(O2oMessageForm vo) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class,
				vo.getPageSize(), vo.getShowPage());
		StringBuilder sql = new StringBuilder();
		sql.append(" select message_id,loanapplyno,receive_name,receive_telphone,content,create_time,message_type,platform_type from o2o_message p where 1=1");
		//单据编号
		if (StringUtils.isNotEmpty(vo.getMessageType())) {
			sql.append(" and p.message_type = ?");
			sqlPageQuery.addParam(vo.getMessageType());
		}
		if(StringUtils.isNotEmpty(vo.getPlatformType())){
			sql.append(" and p.platform_type = ?");
			sqlPageQuery.addParam(vo.getPlatformType());
		}
		if(StringUtils.isNotEmpty(vo.getReceiveName())){
			sql.append(" and p.receive_name like '%?%'"); 
			sqlPageQuery.addParam(vo.getReceiveName());
		}
		if(StringUtils.isNotEmpty(vo.getReceiveTelphone())){
			sql.append(" and p.receive_telphone = ? "); 
			sqlPageQuery.addParam(vo.getReceiveTelphone());
		}
		if(StringUtils.isNotEmpty(vo.getLoanapplyno())){
			sql.append(" and p.loanapplyno = ? "); 
			sqlPageQuery.addParam(vo.getLoanapplyno());
		}
		
		/*if(StringUtils.isNotEmpty(vo.getReceiveName())){
			sql.append(" and p.loan_date >= ?");
			SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd");
			try {
				sqlPageQuery.addParam(s.parse(vo.getLoanDate1()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		if(StringUtils.isNotEmpty(vo.getLoanDate2())){
			sql.append(" and t.loan_date <= ?");
			SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd");
			try {
				sqlPageQuery.addParam(s.parse(vo.getLoanDate2()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}*/
		sql.append(" order by p.create_time desc "); 
		sqlPageQuery.setQuerySql(sql.toString());
		PageResult<Object[]> loanBasepage = o2OMessageDao.findDataWithPage(sqlPageQuery);
		return loanBasepage;
	}
	
	// 执行跑批定时器
	public void dsjMessage(O2oMessageTimer o2oMessageTimer){
		logger.info("手动插入短信数据插入开始==============");
		if(o2oMessageTimer!=null){
			
			 if(o2oMessageTimer.getPlatformType()!=null&&o2oMessageTimer.getMessageType()!=null){
				 String platformType = o2oMessageTimer.getPlatformType() ;
				 String messageType = o2oMessageTimer.getMessageType() ;
				 String date = "";
				 StringBuffer sql= new StringBuffer();
				 if(platformType.equals(O2OMessage.PLATFORM_TYPE_OLD)){ //老系统平台的
					 
					 if(messageType.equals(O2OMessage.MESSAGE_TYPE_FK)){
						 sql.setLength(0); //清空buffer
						 sql.append("select lr.mobile, lr.loanername,rd.refundno,rd.loadapplycode from eadb.O2O_REFUND rd " +
				  					" left join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno" +
				  					" where rd.bankrefundcode = 'GACZ' and rd.billstatus = 'RUN'  and rd.issendmsg = 'N'");
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)||messageType.equals(O2OMessage.MESSAGE_TYPE_DK15)){ // 老系统接口到期的短信
						 sql.setLength(0); //清空buffer
						 sql.append("select lr.mobile, lr.loanername,rl.refundlineno,rd.loadapplycode from eadb.O2O_REFUNDLINE rl left join eadb.O2O_REFUND rd on rd.refundno = rl.refundno " ) ;
						 sql.append(" left join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno ") ;
						 sql.append(" where  rd.billstatus = 'RUN' and rd.bankrefundcode = 'GACZ' and rl.principalremained = 0 ");
						 if(o2oMessageTimer.getTime()!=null){//手动跑批传过来的时间
							 Date secherDate = o2oMessageTimer.getTime();
							 if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)){
								 secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 2);
							 }else{
								 secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 15);
							 }
							 date = DateUtils.formateStandDate(secherDate);
							 sql.append("and '"+date+"' = to_char(rl.interestdate, 'yyyy-MM-dd') ");
						 }else{
							 if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)){
								 sql.append(" and to_char(sysdate + 2, 'yyyy-MM-dd') = to_char(rl.interestdate, 'yyyy-MM-dd') ");
							 }else{
								 sql.append(" and to_char(sysdate + 15, 'yyyy-MM-dd') = to_char(rl.interestdate, 'yyyy-MM-dd') ");
							 }
							
						 }
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_FX2)){ //老系统付息短信
						 sql.setLength(0); //清空buffer
						 sql.append("select lr.mobile, lr.loanername,rl.refundlineno,rd.loadapplycode from eadb.O2O_REFUNDLINE rl left join eadb.O2O_REFUND rd on rd.refundno = rl.refundno " ) ;
						 sql.append(" left join eadb.O2o_Loaner lr on rd.loanapplyno = lr.loanapplyno ") ;
						 sql.append(" where  rd.billstatus = 'RUN' and rd.bankrefundcode = 'GACZ' and rl.principalremained != 0 ");
						 if(o2oMessageTimer.getTime()!=null){
							  Date secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 2);
							 date = DateUtils.formateStandDate(secherDate);
							 sql.append("and '"+date+"' = to_char(rl.interestdate, 'yyyy-MM-dd') ");
						 }else{
							 sql.append(" and to_char(sysdate + 2, 'yyyy-MM-dd') = to_char(rl.interestdate, 'yyyy-MM-dd') ");
						 }
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_YQ2)){  //老系统逾期短信
						 sql.setLength(0); //清空buffer
						 sql.append(" select  lr.mobile, lr.loanername,l.eaid,l.billcode from eadb.o2o_overdue_report l " +
									" left join eadb.O2o_Loanapply ol on ol.billcode = l.billcode left join eadb.O2o_Loaner lr  on ol.loanapplyno = lr.loanapplyno "+
									"where l.status in ('1', '2') and l.bankrefundcode = 'GACZ' ");
						 if(o2oMessageTimer.getTime()!=null){
							  Date secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, -1);
							 date = DateUtils.formateStandDate(secherDate);
							 sql.append("and '"+date+"' =  to_char(l.createtime, 'yyyy-MM-dd') ");
						 }else{
							 sql.append(" and to_char(sysdate - 1, 'yyyy-MM-dd') =  to_char(l.createtime, 'yyyy-MM-dd') ");
						 }
						 
					 }
					
				 }else{//新系统平台的
					 if(messageType.equals(O2OMessage.MESSAGE_TYPE_FK)){
						 sql.setLength(0); //清空buffer
						 sql.append("SELECT lu.user_phone,lu.user_full_name,l.loanapply_no,l.bill_code from o2o_loanapply l  " +
				  					" LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id where l.wf_type = 'O' " );
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)||messageType.equals(O2OMessage.MESSAGE_TYPE_DK15)){ // 老系统接口到期的短信
						 sql.setLength(0); //清空buffer
						 sql.append(" select lu.user_phone,lu.user_full_name,ops.payments_id,l.bill_code from o2o_payments_plan ops ");
						 sql.append(" LEFT JOIN o2o_loanapply l on l.bill_code = ops.bill_code ");
						 sql.append(" LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id ");
						 sql.append(" where residual_principal = 0 ");  
						 if(o2oMessageTimer.getTime()!=null){//手动跑批传过来的时间
							 Date secherDate = o2oMessageTimer.getTime();
							 if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)){
								 secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 2);
							 }else{
								 secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 15);
							 }
							 date = DateUtils.formateStandDate(secherDate);
							 sql.append(" and DATE_FORMAT(payments_date, '%Y-%m-%d') = '"+date+"' ");
						 }else{//不传时间，默认跑当天
							 if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)){
								 sql.append(" and payments_date = adddate(curdate(), '2 days') ");
							 }else{
								 sql.append("  and payments_date = adddate(curdate(), '15 days')   ");
							 }
							
						 }
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_FX2)){ //新系统付息短信
						 sql.setLength(0); //清空buffer
						 sql.append(" select lu.user_phone,lu.user_full_name,ops.payments_id,l.bill_code from o2o_payments_plan ops ");
						 sql.append(" LEFT JOIN o2o_loanapply l on l.bill_code = ops.bill_code ");
						 sql.append(" LEFT JOIN  o2o_loan_user lu on l.loan_id = lu.loan_id ");
						 sql.append(" where residual_principal != 0 ");
						 if(o2oMessageTimer.getTime()!=null){
							  Date secherDate= DateUtils.add(o2oMessageTimer.getTime(), Calendar.DATE, 2);
							 date = DateUtils.formateStandDate(secherDate);
							 sql.append(" and DATE_FORMAT(payments_date, '%Y-%m-%d') = '"+date+"' ");
						 }else{
							 sql.append(" and payments_date = adddate(curdate(), '2 days') ");
						 }
						 
					 }else if(messageType.equals(O2OMessage.MESSAGE_TYPE_YQ2)){  //新系统逾期短信
						//待确认
						 
					 }
					
					 
					 
				 }
				 dosercher(sql.toString(),messageType,date,platformType);
				 logger.info("手动插入短信数据插入结束==============");
			 }else{
				 logger.error("手动跑批平台类型和短信类型不能为空。");
			 }
		}
		
	}
	
	@SuppressWarnings("unused")
	public void dosercher(String sql,String messageType,String date,String platformType){
		int index = 0;//第几页
		int total = 0;//第几条数据
		while (index >= 0) {
			SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, FefundConstants.DATA_LIMIT, index, sql);
			//oracle查询
			PageResult<Object[]> pageResult = null;
			if(platformType.equals(O2OMessage.PLATFORM_TYPE_OLD)){//老系统数据
				pageResult = o2OMessageEaoaDao.findDataWithPage(sqlPageQuery);
			}else{//新系统数据
				pageResult = o2OMessageDao.findDataWithPage(sqlPageQuery);
			}
			
			Integer count = pageResult.getDbRowCount();
			for (int i = 0; i < pageResult.getReturnDataSize(); i++) {
				Object[] obj = pageResult.getData().get(i);
				logger.debug("total:{},{}", ++total, obj.toString());
				String content ="";  //短信内容
				if(messageType.equals(O2OMessage.MESSAGE_TYPE_FK)){  //
					 content = FefundConstants.START_CONTEXT+obj[1]+FefundConstants.FKS_CONTEXT;
				}else if(messageType.equals(O2OMessage.MESSAGE_TYPE_FX2)){
					if(StringUtils.isEmpty(date)){
						 Date secherDate= DateUtils.add(new Date(), Calendar.DATE, 2);
						 date = DateUtils.formateStandDate(secherDate);
					}
					content = FefundConstants.START_CONTEXT+obj[1]+FefundConstants.MIDDLE_CONTEXT+"应于"+date+"还息，"+FefundConstants.BEFORE_CONTEXT;
					
				}else if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK2)){
					if(StringUtils.isEmpty(date)){
						 Date secherDate= DateUtils.add(new Date(), Calendar.DATE, 2);
						 date = DateUtils.formateStandDate(secherDate);
					}
					content = FefundConstants.START_CONTEXT+obj[1]+FefundConstants.MIDDLE_CONTEXT+"应于"+date+"归还本息，"+FefundConstants.BEFORE_CONTEXT2;
					
				}else if(messageType.equals(O2OMessage.MESSAGE_TYPE_DK15)){
					if(StringUtils.isEmpty(date)){
						 Date secherDate= DateUtils.add(new Date(), Calendar.DATE, 15);
						 date = DateUtils.formateStandDate(secherDate);
					}
					content = FefundConstants.START_CONTEXT+obj[1]+FefundConstants.MIDDLE_CONTEXT+"应于"+date+"归还本息，"+FefundConstants.BEFOREEND15_CONTEXT;
					
				}else if(messageType.equals(O2OMessage.MESSAGE_TYPE_YQ2)){
					content = FefundConstants.START_CONTEXT+obj[1]+FefundConstants.OVERDUE_CONTEXT;
				}
				O2OMessage message = new O2OMessage();
				message.setContent(content);
				message.setReceiveTelphone(obj[0].toString());//obj[0].toString()
				message.setReceiveName(obj[1].toString());
				message.setSendName(FefundConstants.SENDNAME);
				message.setCreateTime(new Date());
				message.setSendType(SysMessage.SEND_TYPE_IMMEDIATELY);
				message.setMessageType(messageType);
				message.setPlatformType(platformType);
				message.setRelevanceId(obj[2].toString());
				message.setLoanapplyno(obj[3].toString());
				try {
					boolean flag = o2OMessageDao.isExist(messageType,obj[3].toString());
					if(!flag){
						o2OMessageDao.saveEntity(message);
					}
				} catch (DataIntegrityViolationException e) {
					logger.error("主键重复", e);
				}
				//更新eaoa表中的数据
				if(messageType.equals(O2OMessage.MESSAGE_TYPE_FK)){
					String updatesql = "update eadb.O2O_REFUND set issendmsg = 'Y' where refundno = ?";
					int result = o2OMessageEaoaDao.excuteSql(updatesql,obj[2].toString());
					if(result>0){
						logger.info(obj[2].toString()+"====eaoa中O2O_REFUND表状态修改成功==============");
					}else{
						logger.info(obj[2].toString()+"====eaoa中O2O_REFUND表状态修改失败==============");
					}
				}
				
			}

			if (pageResult.getPageTotal() > index) {
				index++;
			} else {
				index = -1;
			}
		}
	 
	}

	@Transactional("o2oTransactionManager")
	public ModelResult<Boolean> nsEndMessage(String billCode){ //根据贷款单号去查询
		logger.info("开始调用短信接口,贷款编号为:{}", billCode);
		ModelResult<Boolean> modelResult = new ModelResult<Boolean>().withModel(Boolean.TRUE);//根据贷款编号去获取借款人信息，以及信贷经理信息
		O2oLoanapplyEntity loanapply= o2oLoanapplyService.fingByBillCode(billCode);
		 ModelResult<User> result = sysPermissionService.getSysUserById(loanapply.getOperatorNo());//信贷经理id
		 User operator  = result.getModel();
		//借款人信息
		O2oLoanUserEntity loaner = o2oLoanUserService.findById(loanapply.getLoanId(), loanapply.getLoanapplyNo());
		String phone =	loaner.getUserPhone();
		String name = loaner.getUserFullName();
//		String  CustomerCode  = loanapply.getCustomerCode() +"-"+ loanapply.getCustomeRname();
		String contentColleague = FefundConstants.NS_END_COLLEAGUE +"("+ name +")"+FefundConstants.NS_END_COLLEAGUE_END;
		//发给客户
		String contentCustomer = FefundConstants.START_CONTEXT + name +FefundConstants.NS_END_CUSTOMER;
		SmsNotifyRequest  smsCustomerRequest=new SmsNotifyRequest();
		smsCustomerRequest.setRequestId(loanapply.getLoanapplyNo());
		smsCustomerRequest.setBizCode(loanapply.getBillCode());
		smsCustomerRequest.setContent(contentCustomer);
		if(phone.startsWith("+")){
			smsCustomerRequest.setRecipientNumber(phone.substring(1));
		}else{
			smsCustomerRequest.setRecipientNumber(phone);
		}
		
		smsCustomerRequest.setRequestDateTime(new Date());
		smsCustomerRequest.setSmsSendType(SmsSendType.GENERAL);
		smsCustomerRequest.setSystemCode("业务系统");
		smsCustomerRequest.setReceiveName(name);
		smsCustomerRequest.setSendName(FefundConstants.SENDNAME);
		try {
			logger.info("贷款编号：[{}],发送客户手机号:[{}]", loanapply.getBillCode(),phone);
			com.eascs.notify.constant.ModelResult<SmsNotifyResponse> response=smsNotifier.notify(smsCustomerRequest);
			if(!response.isSuccess()){
				modelResult.withError("发送客户短信发送失败原因：", response.getErrMsg());
				logger.info("贷款编号：[{}],发送客户短信发送失败原因:{}", loanapply.getBillCode(),response.getErrMsg());
			}
		} catch (Exception e) {
			logger.error("贷款编号：[{}],发送客户短信发送异常:{}",loanapply.getBillCode(), e.getMessage());
			modelResult.withError("贷款编号：："+loanapply.getBillCode()+",发送客户短信异常：",e.getMessage());
		}
		
		//离职人员不发送
		if(null==operator.getStatus()||!operator.getStatus().equals("0")){
			return modelResult;
		}
		SmsNotifyRequest  smsColleagueRequest=new SmsNotifyRequest();
		try {
			smsColleagueRequest.setRequestId(loanapply.getLoanapplyNo());
			smsColleagueRequest.setBizCode(loanapply.getBillCode());
			smsColleagueRequest.setContent(contentColleague);
			if(operator.getMobile().startsWith("+")){
				smsColleagueRequest.setRecipientNumber(operator.getMobile().substring(1));
			}else{
				smsColleagueRequest.setRecipientNumber(operator.getMobile());
			}
			
			smsColleagueRequest.setRequestDateTime(new Date());
			smsColleagueRequest.setSmsSendType(SmsSendType.GENERAL);
			smsColleagueRequest.setSystemCode("业务系统");
			smsColleagueRequest.setReceiveName(operator.getCname());
			smsColleagueRequest.setSendName(FefundConstants.SENDNAME);
			logger.info("贷款编号：[{}],发送同事手机号:[{}]", loanapply.getBillCode(),operator.getMobile().substring(1));
			com.eascs.notify.constant.ModelResult<SmsNotifyResponse> response=smsNotifier.notify(smsColleagueRequest);
			if(!response.isSuccess()){
				modelResult.withError("发送同事短信发送失败原因：", response.getErrMsg());
				logger.info("贷款编号：[{}],发送同事短信发送失败原因:{}", loanapply.getBillCode(),response.getErrMsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("贷款编号：[{}],发送同事短信发送异常:[{}]",loanapply.getBillCode(), e.getMessage());
			modelResult.withError("贷款编号：："+loanapply.getBillCode()+",发送同事短信异常：",e.getMessage());
		}
		return modelResult;
	}
	
	
	@Transactional("o2oTransactionManager")
	public ModelResult<Boolean> mqsbMessage(String billCode){ //面签申报 银行申报审查节点通过后 发送通知短信
		logger.info("开始调用短信接口,贷款编号为:{}", billCode);
		ModelResult<Boolean> modelResult = new ModelResult<Boolean>().withModel(Boolean.TRUE);//根据贷款编号去获取借款人信息，信贷经理经理信息
		O2oLoanapplyEntity loanapply= o2oLoanapplyService.fingByBillCode(billCode);
		//借款人信息
		O2oLoanUserEntity loaner = o2oLoanUserService.findById(loanapply.getLoanId(), loanapply.getLoanapplyNo());
		
		O2oPaymentDetailVo o2oPaymentDetailVo = o2oPaymentDetailService.findByBillCodeOrLoanapplyNo(loanapply.getLoanapplyNo()); //应交保证金管理费风险补偿金
		
		if(o2oPaymentDetailVo==null){
			modelResult.withError("贷款编号：："+loanapply.getBillCode()+",发送客户短信异常：","应交保证金管理费风险补偿金 实体为空");
			return modelResult;
		}
		
		String phone =	loaner.getUserPhone();
		String name = loaner.getUserFullName();
		String bank_type = loanapply.getBankLoanName(); //放款银行
		String messageContexts = null;
		//发给借款人(根据银行编写短信)
		if(StatusContexts.O2O_BANKTYPE_BC.equals(bank_type)|| StatusContexts.O2O_BANKTYPE_CCBHN.equals(bank_type) ||StatusContexts.O2O_BANKTYPE_CBC.equals(bank_type) 
				 ){
			messageContexts = FefundConstants.START_CONTEXT + name +FefundConstants.MQSB_YHSB_NODE_BC+
					FefundConstants.MQSB_YHSB_NODE_BC_BZJ+o2oPaymentDetailVo.getReceivableBond()+FefundConstants.MQSB_YHSB_NODE_BC_YUAN
					+FefundConstants.MQSB_YHSB_NODE_BC_GLF+o2oPaymentDetailVo.getReceivableManager()+FefundConstants.MQSB_YHSB_NODE_BC_YUAN
					+FefundConstants.MQSB_YHSB_NODE_BC_FXBCJ+o2oPaymentDetailVo.getReceivableRisk()+FefundConstants.MQSB_YHSB_NODE_BC_YUAN
					+FefundConstants.MQSB_YHSB_NODE_BC_END;
		}
		
		if(StatusContexts.O2O_BANKTYPE_GACZ.equals(bank_type)){
			messageContexts =  FefundConstants.START_CONTEXT + name + FefundConstants.MQSB_YHSB_NODE_GAGC;
		}
		SmsNotifyRequest  smsCustomerRequest=new SmsNotifyRequest();
		smsCustomerRequest.setRequestId(loanapply.getLoanapplyNo());
		smsCustomerRequest.setBizCode(loanapply.getBillCode());
		smsCustomerRequest.setContent(messageContexts);
		smsCustomerRequest.setRecipientNumber(phone);
		smsCustomerRequest.setRequestDateTime(new Date());
		smsCustomerRequest.setSmsSendType(SmsSendType.GENERAL);
		smsCustomerRequest.setSystemCode("业务系统");
		smsCustomerRequest.setReceiveName(name);
		smsCustomerRequest.setSendName(FefundConstants.SENDNAME);
		try {
			logger.info("贷款编号：[{}],发送客户手机号:[{}]", loanapply.getBillCode(),phone);
			com.eascs.notify.constant.ModelResult<SmsNotifyResponse> response=smsNotifier.notify(smsCustomerRequest);
			if(!response.isSuccess()){
				modelResult.withError("发送客户短信发送失败原因：", response.getErrMsg());
				logger.info("贷款编号：[{}],发送客户短信发送失败原因:{}", loanapply.getBillCode(),response.getErrMsg());
			}
		} catch (Exception e) {
			logger.error("贷款编号：[{}],发送客户短信发送异常:{}",loanapply.getBillCode(), e.getMessage());
			modelResult.withError("贷款编号：："+loanapply.getBillCode()+",发送客户短信异常：",e.getMessage());
		}
		return modelResult;
	}
	
}
